from obsws_python import ReqClient

# OBS 连接配置
host = "192.168.0.111"
port = 4455
password = "W13YYEkQaHFL6kLT"

media_source_name = "11"

# 定义视频片段起始时间（毫秒）
segments = {
    1: 0,
    2: 60_000,
    3: 120_000,
}

# 创建客户端（同步）
client = ReqClient(host=host, port=port, password=password)

def play_segment(segment_number: int):
    if segment_number not in segments:
        print(f"❌ 片段 {segment_number} 不存在！可选 {list(segments.keys())}")
        return

    start_time = segments[segment_number]

    # 仅跳转到指定时间，OBS 自动播放
    client.set_media_input_cursor(media_source_name, start_time)

    print(f"✅ 已切换到片段 {segment_number}，起始 {start_time/1000:.1f} 秒")

# 主循环
if __name__ == "__main__":
    print("无人直播片段控制器")
    print(f"可用片段: {list(segments.keys())}")
    print("输入片段编号切换，输入 q 退出")

    while True:
        choice = input("请选择片段: ").strip()
        if choice.lower() == "q":
            print("退出控制器")
            break
        if not choice.isdigit():
            print("请输入有效的数字或 q 退出")
            continue
        seg_num = int(choice)
        play_segment(seg_num)
